package com.crr.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class RabbitConfig {
    /**
     * 生成订单的队列
     * @return
     */
    @Bean
    public Queue queue(){
        //消息持久化
        return QueueBuilder.durable("orderQueue")
                .ttl(30*60*1000)
                .build();

    }
    /**
     * 延迟队列
     * @return
     */
    @Bean
    public Queue lazyQueue(){
        return new Queue("lazy-queue");
    }

    /**
     * 延迟交换器
     * @return
     */
    @Bean
    public LazyExchange lazyExchange(){
        return new LazyExchange("lazy-ex");
    }
    @Bean
    public Binding binding(LazyExchange lazyExchange , Queue lazyQueue){
        return BindingBuilder.bind(lazyQueue).to(lazyExchange).with("lazy").noargs();
    }

}
